import Vuex, { Store, Plugin } from 'vuex';

export default class CreateWebSocketPlugin {
  public create(): (store: Store<any>) => void {
    return (store: Store<any>) => {
        if (sessionStorage.store) {
            store.replaceState(JSON.parse(sessionStorage.store));
        }
        store.subscribe((mutation: any) => {
            sessionStorage.setItem('store', JSON.stringify(store.state));
        });
    };
  }
}